<template>
	<view class="min-h-full p-10 static">
		<view class="flex flex-row flex-wrap rounded-lg bg-white" style="min-height: 80vh;box-shadow: 0 0 8px 0px rgba(0,0,0,0.3)">
			<view class="w-full p-20 text-14" style="color: #5E5E5E;">
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-center">
					<text class="text-bold">真实姓名：</text>
					<input class="flex-1 text-14" type="text" placeholder="请输入真实姓名" placeholder-style="color:#B8B8B8" v-model="realname"></input>
				</view>
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-center">
					<text class="text-bold">身份证号：</text>
					<input class="flex-1 text-14" type="text"  maxlength="18" placeholder="请输入身份证号" placeholder-style="color:#B8B8B8" v-model="id_card"></input>
				</view>
				<view class="w-full rounded-sm text-bold text-white text-center text-16 mt-20" style=" height:80rpx; line-height: 80rpx; background-color: #006BFF;" @tap="saveInfo">保存</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	import request from '/utils/request.js';
	export default {
		data() {
			return {
				realname: '',
				id_card: ''
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onLoad() {
			this.realname = this.userInfo.realname;
			this.id_card = this.userInfo.id_card;
			if(!this.userInfo.phone){
				uni.showToast({
					title: '请先登录',
					icon: 'none',
				})
				setTimeout(()=>{
					uni.navigateBack()
				}, 1000)
			}
		},
		onReachBottom() {
			
		},
		onShareAppMessage() {
			return {
			  title: '飞兔接单',
			  path: '/pages/task/list',
			  // imageUrl : ''
			}
		},
		onShareTimeline() {
			return {
			  title: '飞兔接单',
			  // query: '',
			  // imageUrl : ''
			}
		},
		methods: {
			...mapMutations(['login', 'setUserInfo']),
			// 保存信息
			saveInfo(){
				request.post('/pilot/saveInfo', {
					realname: this.realname,
					id_card: this.id_card,
				}).then(res=>{
					uni.showToast({
						title: '保存成功'
					})
					request.post('pilot/userInfo').then(res=>{
						this.setUserInfo(res);
						setTimeout(()=>{
							uni.navigateBack()
						}, 1000)
					})
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFF8F5;
	}
	.bottom-line{
		border-bottom: 1px solid #bbb;
	}
</style>
